package com.atiguigu.springcloud.controller;

import com.atguigu.springcloud.entity.CommonResult;
import com.atguigu.springcloud.entity.Payment;
import com.atiguigu.springcloud.clients.PaymentClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author lizhilong
 * @create 2020/5/3 12:59
 * @desc
 */
@RestController
@Slf4j
public class PaymentController {

    @Resource
    private PaymentClient paymentClient;

    @GetMapping("/payment/ok/{id}")
    public CommonResult<Payment> getOK(@PathVariable("id") Integer id){
        CommonResult commonResult = paymentClient.get(id);
        return commonResult;
    }


    @GetMapping("/payment/timeout/{id}")
    public CommonResult<Payment> getTimeout(@PathVariable("id") Integer id){
        log.info("开始时间：{}",System.currentTimeMillis());
        CommonResult commonResult = paymentClient.getTimeout(id);
        log.info("结束时间：{}",System.currentTimeMillis());
        return commonResult;
    }


    @GetMapping("/payment/break/{id}")
    public CommonResult<String> breakTest(@PathVariable("id") Integer id){
        log.info("开始时间：{}",System.currentTimeMillis());
        CommonResult<String> commonResult = paymentClient.breakTest(id);
        log.info("结束时间：{}",System.currentTimeMillis());
        return commonResult;
    }
}
